MYPUBLICKEY = 'a50'
PoolData = []
PeerList = []
LinkList = []
BlockNum = 0
OtherNum = []

ORDERPORT=[('127.0.0.1', 11181), ('127.0.0.1', 11182), ('127.0.0.1', 11183)]

ID = 'ORDER'

MAXDATANUM = 10240

MYNAME = 'peer1'

def pooldb(tp, time, name, desc, hashs, point):
    '''
        查询、插入pool.db
        ARGVS:
            tp: int 0=>查询 1=>插入新数据 2=>插入point数据
            其它数据: 如无则为NONE 
        RETURNS:
            查询时,返回列表数据或[]
            插入时,返回TURE FALSE
            入参错误时,返回NONE
    '''
    db = sqlite3.connect('data/pool.db')
    cur = db.cursor()
    sql =''
    if tp == 0:
        temp = setSQL(time, name, desc, hashs, point)
        sql = 'select * from BUFFERPOOL where ' + temp
        result = cur.execute(sql).fetchall()
        db.close()
        return result
    if tp == 1:
        if time and name and desc and hashs:
            sql = 'insert into BUFFERPOOL(time,name,desc,hash) values(?,?,?,?)'
            try:
                cur.executemany(sql, [(time, name, desc, hashs)])
                db.commit()
                return True
            except:
                return False
        else:
            return None
    if tp == 2:
        if point:
            temp = setSQL(time, name, desc, hashs, None)
            sql = 'update BUFFERPOOL set point=' + str(point) + 'where ' + temp
            try:
                cur.execute(sql)
                db.commit()
                return True
            except:
                return False
        else:
            return None
    db.close()
def setSQL(time, name, desc, hashs, point):
    temp = ''
    ad = ''
    if time:
        temp += 'time=' + str(time)
        ad = ' and '
    if name:
        temp += ad + 'name="' + name + '"'
        ad = ' and '
    if desc:
        temp += ad + 'desc="' + desc + '"'
        ad = ' and '
    if hashs:
        temp += ad + 'hash="' + hashs + '"'
        ad = ' and '
    if point:
        temp += ad + 'point=' + str(point)
    return temp
    
    